package com.wjw.spring5.collectionDI.factorybean;

import com.wjw.spring5.collectionDI.Course;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author wjw
 * @date 2021年10月27日 23:46
 */
public class MyBean implements FactoryBean<Course> {
    // 定义返回的bean对象 在FactoryBean加泛型
    @Override
    public Course getObject() throws Exception {
        // 底层使用工厂加反射
        ApplicationContext context = new ClassPathXmlApplicationContext("factorybean.xml");
        Course course = context.getBean("course", Course.class);
        return course;
    }

    @Override
    public Class<?> getObjectType() {
        return null;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }
}
